#ifndef _TEVENTLOOP_H_
#define _TEVENTLOOP_H_
#include <map>
#include <vector>
#include "tnocopyable.h"
#ifdef WIN32
#include <windows.h>
#else
#include <unistd.h>
#include <errno.h>
#include <sys/epoll.h>
#define MAX_EVENTS 1024
#endif

namespace tlib
{
class TSocket;
class TServer;
class TEventLoop: TNoCopyable
{
public:
	TEventLoop();
	virtual ~TEventLoop();

	bool AddLoop(int fd);
	bool DelLoop(int fd);
	void RunLoop(TServer* srv);
private:
#ifdef WIN32
	struct timeval m_timeout;
	std::map<int, TClient*> m_conns;
	fd_set m_connSet, m_sendSet, m_recvSet;
#else
	int m_epollfd;
	std::vector<TClient*> m_conns;
	struct epoll_event m_ev, m_events[MAX_EVENTS];
#endif
	TBufferPool m_bufferPool;
};
}

#endif
